Title: SQL W3S (By-BKK) / 030 Self Join
Tags: Obsidian_to_Anki

Q: What is a self join in SQL?
A: A self join is a regular join where a table is joined with itself

Q: Why do we use a self join in SQL?
A: To connect rows within the same table based on related column values

Q: True or False: In a self join, two different tables are joined together
A: False

Q: Which SQL clause is used to set different aliases for the same table in a self join?
A: The FROM clause (with table aliases like T1, T2, or A, B)

Q: What does the condition "A.CustomerID <> B.CustomerID" ensure in a self join example?
A: It prevents comparing the same row to itself

Q: Give an example use-case for a SQL self join
A: Finding customers from the same city within a customers table

Q: Show the basic SQL syntax for a self join
A: SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition;

Q: Fill in the blank: In a self join, table aliases help differentiate between __
A: Different instances of the same table

Q: True or False: Self joins require at least two different tables in the database
A: False

Q: Reverse card:
What is the syntax for a SQL self join?
A: SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition;